﻿using CastingWellEquipmentGUI.Model;
using CastingWellEquipmentGUI.ViewModel.Common.LogTool;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CastingWellEquipmentGUI.Utils
{
    /// <summary>
    /// 系统共通方法
    /// </summary>
    public static class SysCommon
    {
        /// <summary>
        /// 获取当前页控件
        /// </summary>
        /// <param name="showPageTitle">当前页名称</param>
        /// <returns></returns>
        public static HashSet<Control> getCurrentControl(string showPageTitle)
        {
            HashSet<Control> tempHashSet = new HashSet<Control>();
            for (int i = 0; i < LogTool.CurrentUser.Roles.Count; i++)
            {
                for (int j = 0; j < LogTool.CurrentUser.Roles[i].Permissions.Count; j++)
                {
                    if (LogTool.CurrentUser.Roles[i].Permissions[j].PControl == null)
                    {
                        continue;
                    }
                    if (LogTool.CurrentUser.Roles[i].Permissions[j].PForm != null &&
                        LogTool.CurrentUser.Roles[i].Permissions[j].PForm.FormName == showPageTitle)
                    {
                        tempHashSet.Add(LogTool.CurrentUser.Roles[i].Permissions[j].PControl);
                    }
                }
            }
            return tempHashSet;
        }
    }
}
